<?php

class video_ctrl extends Controller
{


    //////每一个都进行单个提交

    public function __construct()
    {
        parent::__construct();

    }

    //获取视频
    public function get_video()
    {
        if (!$this->ajax_err) {
            $pageNo = (!empty($_REQUEST['pageNo'])) ? (int)($_REQUEST['pageNo']) : 1;
            $pageSize = (!empty($_REQUEST['pageSize'])) ? (int)($_REQUEST['pageSize']) : 40;

            $_mdl = Loader::mdl("video_mdl");
            $data = $_mdl->get_video($pageNo, $pageSize);
            $this->ajax($data);
        } else {
            return $this->ajax('', array(1, '未登录', 1, '请登录'));
        }
    }

    //点击增加
    public function add_count()
    {
        if (!$this->ajax_err) {
            $id = $_REQUEST["id"];
            $count = $_REQUEST["count"];

            $_mdl = Loader::mdl("video_mdl");
            $_mdl->add_count($id, $count);
        } else {
            return $this->ajax('', array(1, '未登录', 1, '请登录'));
        }
    }

    //增加视频
    public function save_video()
    {
        if (!$this->ajax_err && $this->uid) {
            $id = (empty($_REQUEST['id']))?  0 : $_REQUEST['id'];
            $src = $_REQUEST["src"];
            $name = $_REQUEST["name"];
            $pic = $_REQUEST["pic"];

            $_mdl = Loader::mdl("video_mdl");
            $data = $_mdl->add_video($id, $name, $pic, $src);
            $this->ajax($data);
        } else {
            return $this->ajax('', array(1, '未登录', 1, '请登录'));
        }
    }


    //删除视频
    public function delete_video()
    {
        if (!$this->ajax_err && $this->uid) {
            $id = $_REQUEST["id"];
            $_mdl = Loader::mdl("video_mdl");
            $result = $_mdl->delete_video($id);
            $this->ajax($result);
        } else {
            return $this->ajax('', array(1, '未登录', 1, '请登录'));
        }
    }

}